<?php
/**
 * User: lsx
 * Date: 2017/4/22
 * Time: 10:09
 * Progress:0%
 */

namespace app\wechat\controller;


use icontroller\admin\AController;
use icontroller\admin\wechat\IWechatTemplateMessage;
use library\tencent\wechat\admin_wechat\SendTemplateMessage;
use logic\admin\wechat\LWechatTemplateMessage;
use think\Db;

class WechatTemplateMessage extends AController implements IWechatTemplateMessage
{
    private $logic;
    function __construct()
    {
        parent::__construct();
        $this->logic=new LWechatTemplateMessage();
    }

    public function index(){
        return view();
    }
    public function index_data(){
        $param=array(
            'keyword'=>input('keyword'),
            'limit'=>input('limit'),
            'offset'=>input('offset'),
            'ordinal'=>input('ordinal'),
            'order'=>input('order'),
        );
        return $this->logic->index_data($param);
    }
    public function add(){
        $short=Db::name('wechat_variable_category')->select();
        $this->assign('short_id',$short);
        return $this->view->fetch(isset($this->template)?$this->template:"add");
    }

    public function insert()
    {
        $param=array(
            'title'=>input('title'),
            'template_id'=>input('template_id'),
            'template_short_id'=>input('template_short_id'),
            'url'=>input('url')
        );

        return $this->logic->insert_data($param);
    }

    public function edit(){
        $id=input('id');
        $data=$this->logic->edit_index($id);
        $this->assign('vo',$data);
        return $this->view->fetch();
    }

    public function update()
    {
        $id=input('id');
        $param=array(
            'title'=>input('title'),
            'template_short_id'=>input('template_short_id'),
            'template_id'=>input('template_id'),
            'url'=>input('url')
        );
        return $this->logic->update_data($param,$id);
//        $id=input('id');
//        $key=input('tp_kw/a');
//        $value=input('tp_value/a');
//        $color=input('tp_color/a');
//        $param=array(
//            'title'=>input('title'),
//            'template_short_id'=>input('template_short_id'),
//            'template_id'=>input('template_id'),
//            'url'=>input('url')
//        );
//        return $this->logic->update_data($param,$key,$value,$color,$id);
    }

    public function changeStatus(){

        $param=array(
            'id'=>input('id'),
            'status'=>input('status')
        );
        return $this->logic->change_data_status($param);

    }

    public function delete(){
        $id=input('id');
        return $this->logic->delete_data($id);
    }

    public function get_valiable_value(){
        $short_id=input('short_id');
        $data=Db::name('wechat_template_variable')->where(['category_id'=>$short_id])->select();
        return array(
            'message'=>'查询成功',
            'success'=>true,
            'data'=>$data
        );
    }

    public function ecc(){
        $data=array(
            'touser'=>"oy2HRv8Pak3uXD1ya-Q3V9wbEONw",
            'keyword1'=>'15723772012',
            'keyword2'=>'长期有效'
        );
        $res=SendTemplateMessage::send_message("OPENTM200605630",$data);
        var_dump($res);
    }

}